package streamApi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Stream是关注的是对数据的运算与CPU打交道
 * 集合关注的是数据的存储与内存打交道
 * <p>
 * Stream的三个特点：
 * 1.stream自身不会存储数据
 * 2.stream不会改变源对象，只会返回一个带有新结果的stream对象
 * 3.stream的操作是延迟的，只有在真正需要结果的时候才会执行stream的操作
 * <p>
 * 创建Stream的4中方式:
 * 1.通过集合
 * 2.通过数组
 * 3.通过Stream类本身
 */
public class Demo01 {
    public static void main(String[] args) {
        List<PatientTemperatureVo> patientTemperatureVos = getPatientList();
        //1.通过集合创建stream
        //返回一个顺序流
        Stream<PatientTemperatureVo> stream = patientTemperatureVos.stream();

        //返回一个并行流
        Stream<PatientTemperatureVo> parallelStream = patientTemperatureVos.parallelStream();

        //2.通过数组创建stream
        int[] arr = new int[]{1, 2, 3};
        IntStream intStream = Arrays.stream(arr);

        //3.通过stream本身的静态方法
        Stream<Integer> integerStream = Stream.of(1, 2, 3);

        //4.创建无限流
        Stream.iterate(0, t -> t + 2).limit(10).forEach(System.out::println);
        Stream.generate(Math::random).limit(10).forEach(System.out::println);
    }

    public static List<PatientTemperatureVo> getPatientList() {
        List<PatientTemperatureVo> list = new ArrayList<>();
        list.add(new PatientTemperatureVo("赵六", "2020-01-25 12:13:26", 37.2));
        list.add(new PatientTemperatureVo("王五", "2020-01-25 12:13:26", 36.5));
        list.add(new PatientTemperatureVo("张三", "2020-01-24 12:25:26", 36.2));
        list.add(new PatientTemperatureVo("李四", "2020-01-25 12:24:26", 36.5));
        list.add(new PatientTemperatureVo("李四", "2020-01-24 21:13:25", 36.9));
        list.add(new PatientTemperatureVo("张三", "2020-01-25 11:13:26", 36.7));
        list.add(new PatientTemperatureVo("张三", "2020-01-27 12:13:26", 36.3));
        list.add(new PatientTemperatureVo("张三", "2020-01-28 12:35:23", 36.4));
        list.add(new PatientTemperatureVo("李四", "2020-01-27 13:15:26", 37));
        list.add(new PatientTemperatureVo("李四", "2020-01-23 15:13:26", 36.6));
        list.add(new PatientTemperatureVo("赵六", "2020-01-24 12:13:26", 36.9));
        list.add(new PatientTemperatureVo("王五", "2020-01-27 12:25:54", 36.4));
        list.add(new PatientTemperatureVo("李四", "2020-01-26 12:13:26", 36.2));
        list.add(new PatientTemperatureVo("李四", "2020-01-28 19:13:26", 36.1));
        list.add(new PatientTemperatureVo("黄七", "2020-01-23 12:13:26", 36.9));
        list.add(new PatientTemperatureVo("黄七", "2020-01-26 06:13:26", 37.5));
        list.add(new PatientTemperatureVo("王五", "2020-01-23 12:13:26", 36.2));
        list.add(new PatientTemperatureVo("王五", "2020-01-24 18:13:21", 36.9));
        list.add(new PatientTemperatureVo("刘八", "2020-01-26 12:13:26", 36.8));
        list.add(new PatientTemperatureVo("黄七", "2020-01-25 12:13:26", 37.2));
        list.add(new PatientTemperatureVo("黄七", "2020-01-28 12:13:26", 35.9));
        list.add(new PatientTemperatureVo("赵六", "2020-01-26 12:14:26", 37.5));
        list.add(new PatientTemperatureVo("刘八", "2020-01-25 17:13:23", 36.5));
        list.add(new PatientTemperatureVo("王五", "2020-01-26 12:13:26", 36.8));
        list.add(new PatientTemperatureVo("王五", "2020-01-28 12:13:26", 36.1));
        list.add(new PatientTemperatureVo("赵六", "2020-01-27 08:12:46", 37.9));
        list.add(new PatientTemperatureVo("黄七", "2020-01-24 12:13:26", 37.1));
        list.add(new PatientTemperatureVo("黄七", "2020-01-27 12:43:26", 37.1));
        list.add(new PatientTemperatureVo("刘八", "2020-01-23 11:13:26", 36.1));
        list.add(new PatientTemperatureVo("刘八", "2020-01-28 12:13:26", 36.3));
        list.add(new PatientTemperatureVo("张三", "2020-01-23 12:13:26", 36.5));
        return list;
    }
}
